﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Collections.Generic;

namespace WebSite.MasterPages
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LinqDataSource_NoticiasRecientes_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            BLL.DataContextClassesBoletin.DataClassesDataContext DB = new BLL.DataContextClassesBoletin.DataClassesDataContext();

            e.Result = (from p in DB.Publicaciones
                        where p.EstaPublicada == true
                        orderby p.FechaCreacion descending
                        select new
                        {
                            ID = p.ID_Publicacion,
                            Titulo = p.Titulo,
                            Descripcion = p.Descripcion,
                            FechaCreacion = p.FechaCreacion.Value.ToShortDateString()
                        }).Take(3);
        }

        protected void GridView_NoticiasRecientes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Retrieve the GridView control in the second column.
                ((HyperLink)e.Row.Cells[0].FindControl("HyperLink_LeerMas")).NavigateUrl = ConfigurationManager.AppSettings["URLBoletin"].ToString() +
                                                                                           "post.aspx?id=" +      //url.com/post.aspx?id=publication_id
                                                                                           DataBinder.Eval(e.Row.DataItem, "ID").ToString();
                
            }
        }
    }
}
